<?php

/**
 * 检测是否本地，开发，测试环境
 * @return bool
 */

use Psr\Log\LoggerInterface;

if (!function_exists('check_dev_env')) {
    function check_dev_env()
    {
        return in_array(config('APP_ENV'), ['local', 'dev', 'test']);
    }
}

if (!function_exists('check_app_new')) {
    function check_app_new()
    {
        return in_array(env('APP_NAME', ''), ['jikeliao', 'miai']);
    }
}

/**
 * 检测是否本地，开发环境
 * @return bool
 */
if (!function_exists('check_debug_env')) {
    function check_debug_env()
    {
        return in_array(config('APP_ENV'), ['local', 'dev']);
    }
}


/**
 * 获取日志接口
 */
if (!function_exists('get_logger')) {
    function get_logger($name = 'app', $group = "app"): LoggerInterface
    {
        return \Hyperf\Utils\ApplicationContext::getContainer()->get(\Hyperf\Logger\LoggerFactory::class)->get($name, $group);
    }
}


/**
 * 获取日志接口
 */
if (!function_exists('log_debug')) {
    function log_debug($msg, $content = [], $name = 'app', $group = "app")
    {
        get_logger($name, $group)->debug($msg, $content);
    }
}

/**
 * 打印日志
 */
if (!function_exists('log_info')) {
    function log_info($msg, $content = [], $name = 'app', $group = "app")
    {
        get_logger($name, $group)->info($msg, $content);
    }
}

/**
 * 打印接口结果
 */
if (!function_exists('log_user_result')) {
    function log_user_result($userId, $msg = '')
    {
        $traces = debug_backtrace();
        $class = $traces[1] ? $traces[1]['class'] : '';
        $func = $traces[1] ? $traces[1]['function'] : '';
        log_info("{$class}::{$func}=={$userId}==" . (is_string($msg) ? $msg : json_encode($msg)));
    }
}


/**
 * 获取日志接口
 */
if (!function_exists('log_notice')) {
    function log_notice($msg, $content = [], $name = 'app', $group = "app")
    {
        get_logger($name, $group)->notice($msg, $content);
    }
}

/**
 * 获取日志接口
 */
if (!function_exists('log_error')) {
    function log_error($msg, $content = [], $name = 'app', $group = "app")
    {
        get_logger($name, $group)->error($msg, $content);
    }
}

/**
 * 筛选applepay项
 */
if (!function_exists('filter_applepay')) {
    function filter_applepay($arr = [])
    {
        return $arr['subject_id'] > 100;
    }
}

/**
 * 筛选其他充值项
 */
if (!function_exists('filter_otherpay')) {
    function filter_otherpay($arr = [])
    {
        return $arr['subject_id'] < 100;
    }
}
